package main

import (
	"fmt"
)

func main() {

	s1 := []int{1, 2, 3, 4, 5}
	fmt.Printf("slice s1 : %v\n", s1)
	s2 := make([]int, 10)
	fmt.Printf("slice s2 : %v\n", s2)
	copy(s2, s1)
	fmt.Printf("copied slice s1 : %v\n", s1)
	fmt.Printf("copied slice s2 : %v\n", s2)
	s3 := []int{1, 2, 3}
	fmt.Printf("slice s3 : %v\n", s3)
	s3 = append(s3, s2...)
	fmt.Printf("appended slice s3 : %v\n", s3)
	s3 = append(s3, 4, 5, 6)
	fmt.Printf("last slice s3 : %v\n", s3)

	fmt.Println("---------------------------")

	data := [...]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	fmt.Println("array data : ", data)
	s11 := data[8:]
	s12 := data[:5]
	fmt.Printf("slice s11 : %v\n", s11)
	fmt.Printf("slice s12 : %v\n", s12)
	copy(s12, s11)
	fmt.Printf("copied slice s11 : %v\n", s11)
	fmt.Printf("copied slice s12 : %v\n", s12)
	fmt.Println("last array data : ", data)

	slice := data[:]
	for index, value := range slice {
		fmt.Printf("index : %v , value : %v\n", index, value)
	}
	fmt.Println("---------------------------")

	var a = []int{1, 3, 4, 5}
	fmt.Printf("slice a : %v , len(a) : %v, cap(a): %v\n", a, len(a), cap(a))
	b := a[1:2]
	fmt.Printf("slice b : %v , len(b) : %v, cap(b): %v\n", b, len(b), cap(b))
	c := b[0:3]
	fmt.Printf("slice c : %v , len(c) : %v, cap(c): %v\n", c, len(c), cap(c))

	str := "hello world"
    s71 := str[0:5]
    fmt.Println(s71)

    s72 := str[6:]
    fmt.Println(s72)

	s := []byte(str) //中文字符需要用[]rune(str)
    s[6] = 'G'
    s = s[:8]
    s = append(s, '!')
    str = string(s)
    fmt.Println(str)


	str1 := "你好，世界！hello world！"
    ss12 := []rune(str1)
    ss12[3] = '够'
    ss12[4] = '浪'
    ss12[12] = 'g'
    ss12 = ss12[:14]
    str1 = string(ss12)
    fmt.Println(str1)

	slice1 := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
    d1 := slice1[6:8]
    fmt.Println(d1, len(d1), cap(d1))
    d2 := slice1[:6:8]
    fmt.Println(d2, len(d2), cap(d2))


}
